
#include <iostream>

using namespace std;

const int N = 1e5 + 10;

int Ele[N];
int Dp[N];
int ans = INT_MIN;

int main()
{
	int n; cin >> n;
	for (int i = 0; i < n; i++) cin >> Ele[i];
	Dp[0] = Ele[0];

	for (int i = 1; i < n; i++) {
		Dp[i] = max(Dp[i - 1] + Ele[i], Ele[i]);
		ans = max(ans, Dp[i]);
	}

	cout << ans;
	return 0;
}
